package two;

import java.util.Arrays;
import java.util.Scanner;

public class test17087 {
    private static char[] b;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n =scanner.nextInt();
        char[] array = new char[n];
        String s =scanner.next();
        for (int i = 0; i < n; i++) {
            array[i]=s.charAt(i);
        }
        Arrays.sort(array);
        for (int i = 0; i < n; i++) {
            b=new char[i+1];
            Perm(array,0,n,i+1);
        }
    }

    private static int t=0;
    private static void Perm(char[] a,int index,int n, int m) {
        if(m==0){
            t++;
            System.out.print(t+" ");
            for (int i = 0; i <b.length; i++) {
                System.out.print(b[i]);
            }
            System.out.println();
        }else if(n==m){
            b[index] = a[a.length - n];
            index++;
            Perm(a,index, n - 1, m - 1);
        }
        else{
            b[index] = a[a.length - n];
            index++;
            Perm(a,index, n - 1, m - 1);
            index--;
            Perm(a,index, n - 1, m);
        }
    }
}
